package com.martin.study;

import java.beans.PropertyEditor;
import java.beans.PropertyEditorSupport;

public class JdkPropertyEditorDemo extends PropertyEditorSupport implements PropertyEditor {
	public static void main(String[] args) {
		JdkPropertyEditorDemo demo = new JdkPropertyEditorDemo();
		demo.setAsText("孔超#男");
		User value = (User) demo.getValue();
		System.out.println(value);
	}

	@Override
	public void setAsText(String text) throws IllegalArgumentException {
		User user = new User();
		String[] args = text.split("#");
		user.name = args[0];
		user.gender = args[1];
		this.setValue(user);
	}

	public static class User {
		public String name;
		public String gender;

		@Override
		public String toString() {
			return "User{" +
					"name='" + name + '\'' +
					", gender='" + gender + '\'' +
					'}';
		}
	}
}
